package com.sy.module_clockin.db

import androidx.room.*
import com.sy.module_clockin.annotation.ClockInType
import com.sy.module_clockin.db.dbsheet.ClockInData
import kotlinx.coroutines.flow.Flow


@Dao
interface ClockInDataDao {

    @Query("SELECT * FROM ClockInData where clockInType=:clockInType and recordTime >= :startTime and recordTime <= :endTime  ORDER  BY  recordTime desc ")
    fun getClockInByTimeRangeAndType(@ClockInType clockInType: Int, startTime: Long, endTime: Long): Flow<List<ClockInData>>

    @Query("SELECT * FROM ClockInData where  recordTime >= :startTime and recordTime <= :endTime ORDER  BY  recordTime desc ")
    fun getClockInByTimeRange(startTime: Long, endTime: Long): Flow<List<ClockInData>>

    @Query("SELECT COUNT(id) FROM ClockInData ")
    fun getClockInCount(): Flow<Int>

    @Insert(onConflict = OnConflictStrategy.REPLACE)
    fun saveClockIn(clockInData: ClockInData): Long

    @Delete
    fun deleteClockIn(clockInData: ClockInData): Int

    @Update
    fun updateClockIn(clockInData: ClockInData): Int
}